<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;

class Course extends Controller
{
   public function index(){
       	$course=Db::name("course")->select();
       	// dump($shop);exit;
       	$this->assign("course",$course);
       	return $this->fetch();
       }
        public function delete($id){
        $coures=Db::name("course")->find($id);
       	if(Db::name("course")->delete($id)) 
       	{
       	   $this->success('删除成功');
       	}else $this->fail('删除失败');
       }
      public function add(){
    return $this->fetch();
}

public function courseadd(){
       $file = request()->file('pic'); 
        //移动到框架应用根目录/public/static/images/ 目录下 
       var_dump($file);
        if($file){
          $info = $file->rule('uniqid')->move(ROOT_PATH . 'public' . DS . 'static'. DS . 'imagecourse'); 
          if ($info) { 
              $filename=$info->getFilename(); 
          } else { 
              $this->error($file->getError()); 
          } 
        }

    if(request()->isPost()){
     
      $data=[
          'clubid'=>input('param.clubid'),
        'coursename'=>input('param.coursename'),
        'courseprice'=>input('param.courseprice'),
        'courserank'=>input('param.courserank'),
        'courserecom'=>input('param.courserecom'),
          'coursestate'=>0

      ];
    }
 
   $res=Db::name("course")->insert($data);
    if($res){
      $this->redirect('course/index',5,'新增课程成功');
    }else{
      $this->error("新增课程失败");
    }
    return $this->fetch();
  }

public function edit(){
    $id=input('param.id');
    $course=Db::name('course')->find($id);
    $this->assign("course",$course);
    return $this->fetch();
}

public function update(){
   $file = request()->file('pic'); 
        //移动到框架应用根目录/public/static/images/ 目录下 
       var_dump($file);
        if($file){
          $info = $file->rule('uniqid')->move(ROOT_PATH . 'public' . DS . 'static'. DS . 'imagecourse'); 
          if ($info) { 
              $filename=$info->getFilename(); 
          } else { 
              $this->error($file->getError()); 
          } 
        }

    if(request()->isPost()){
     
      $data=[
        'courseid'=>input('param.courseid'),
        'clubid'=>input('param.clubid'),
          'courseprice'=>input('param.courseprice'),
        'coursename'=>input('param.coursename'),
        'courserank'=>input('param.courserank'),
        'courserecom'=>input('param.courserecom'),
      ];
    }
 
   $res=Db::name("course")->update($data);
    if($res){
      $this->redirect('course/index',5,'修改课程成功');
    }else{
      $this->error("修改课程失败");
    }
    return $this->fetch();
  }
}